package design.pattern.Combination.impl;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件夹目录 实现类
 *
 * @author lihh
 */
public class Directory extends Entry {
  private String name;
  private List<Entry> list = new ArrayList<>();
  
  public Directory(String name) {
    this.name = name;
  }
  
  
  @Override
  public String getName() {
    return this.name;
  }
  
  @Override
  public int getSize() {
    int totalSize = 0;
    
    for (Entry entry : list)
      totalSize += entry.getSize();
    return totalSize;
  }
  
  @Override
  public Entry add(Entry entry) {
    this.list.add(entry);
    return this;
  }
  
  @Override
  public void printList(String prefix) {
    String basePath = prefix + "/" + this.getName();
    
    System.out.println(basePath + "(" + this.getSize() + ")");
    for (Entry entry : list)
      entry.printList(basePath);
  }
}
